//
//  LYQIntegralDescriptionViewController.m
//  ZCProject
//
//  Created by Zheng on 16/12/6.
//  Copyright © 2016年 Zheng. All rights reserved.
//

#import "LYQIntegralDescriptionViewController.h"

#import "LYQIntegralHeaderView.h"
#import "LYQIntegralDescriptionCell.h"

#define kIntegralDescripitionCell_ID @"kIntegralDescripitionCell_ID"

@interface LYQIntegralDescriptionViewController () <UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) LYQIntegralHeaderView *headerView;
@property (nonatomic, strong) NSArray *contentArr; //内容
@property (nonatomic, strong) NSArray *lengthArr; //需要修改属性的长度

@end

@implementation LYQIntegralDescriptionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"积分说明";
    
    self.listTableView.delegate = self;
    self.listTableView.dataSource = self;
    [self.listTableView registerNib:[UINib nibWithNibName:@"LYQIntegralDescriptionCell" bundle:nil]forCellReuseIdentifier:kIntegralDescripitionCell_ID];
    self.listTableView.estimatedRowHeight = 100;
    self.listTableView.rowHeight = UITableViewAutomaticDimension;
    
    _contentArr = @[@"Q1：积分是什么?\n积分是旅业圈的虚拟分值体系,旨在有效的维护市场环境,让有价值的资源、需求、知识等得到认可",
                    @"Q2：积分如何获取?\na.每日登录\n  5积分/日\nb.分享旅业圈内容\n  5积分/次  每日上限 10\nc.发布话题的观点和评论\n  2积分/条  每日上限 10",
                    @"Q3：积分的使用\n积分属于增值服务。除每日赠送沟通次数外,可以使用积分增加联系业务,为你拓展业务,提供帮助。",
                    @"Q4：积分的有效期?\n积分长期有效,后续升级版本中,积分将有更多的用武之地,请放心积累吧。",
                    @"联系助手,了解更多神秘积分获取方法"];
    
    _lengthArr = @[@"9",@"10",@"8",@"10",@"0"];
}

#pragma mark - tableview sourcedata
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    LYQIntegralDescriptionCell *cell = [tableView dequeueReusableCellWithIdentifier:kIntegralDescripitionCell_ID forIndexPath:indexPath];
    
    NSMutableAttributedString *contentStr = [[NSMutableAttributedString alloc] initWithString:_contentArr[indexPath.row]];
    
    [contentStr addAttribute:NSForegroundColorAttributeName value:kLYQBlack range:NSMakeRange(0, [_lengthArr[indexPath.row] integerValue])];
    
    [contentStr addAttribute:NSFontAttributeName value:kWFont(15) range:NSMakeRange(0, [_lengthArr[indexPath.row] integerValue])];
    
    if (indexPath.row != 4) {
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        [paragraphStyle setLineSpacing:7];
        [contentStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [contentStr length])];
    } else {
        cell.textLbl.textColor = RGB(64, 162, 229, 1);
    }
    
    cell.textLbl.attributedText = contentStr;
    
    return cell;
}

#pragma mark - tableview delegate
#pragma mark 头视图高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return kWScale(50);
}

#pragma mark 自定义头视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    _headerView = [[LYQIntegralHeaderView alloc] init];
    _headerView.titleLbl.text = @"我的积分 : 10";
    _headerView.instructionsBtn.hidden = YES;
    
    return _headerView;
}

#pragma mark 设置分割线偏移量
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsMake(0, 10, 0, 0)];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsMake(0, 10, 0, 0)];
    }
}

#pragma mark 单元格点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == 4) {
        NSLog(@"联系助手");
    }
}

#pragma mark - 内存警告
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
